# coding=utf-8
from bs4 import BeautifulSoup
html_doc = """
<html><head><title>The Dormouse's story</title></head>
<body>
<h1><a href="http://example.com/elsie" class="sister" id="link1">Elsie</a></h1>
<h1><a href="http://example.com/elsie" class="sister" id="link2">Elsie1</a></h1>
<p class="title"><b>The Dormouse's story</b></p>

<p class="story">Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
and they lived at the bottom of a well.</p>

<p class="story">...</p>
"""

soup = BeautifulSoup(html_doc)
tag = soup.h1
print tag

a = tag.a
print a
print type(a)
print
print a.__dict__
print
print a['href']

all_h1 = soup.find_all('h1')
print type(all_h1)
for h1 in all_h1:
    print h1.a['href']
    
# <h1><a class="sister" href="http://example.com/elsie" id="link1">Elsie</a></h1>
# <a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>
# <class 'bs4.element.Tag'>
# 
# {'can_be_empty_element': False, 'previous_element': <h1><a class="sister" href="
# http://example.com/elsie" id="link1">Elsie</a></h1>, 'next_sibling': None, 'name
# ': u'a', 'parent': <h1><a class="sister" href="http://example.com/elsie" id="lin
# k1">Elsie</a></h1>, 'namespace': None, 'prefix': None, 'previous_sibling': None,
#  'attrs': {u'href': u'http://example.com/elsie', u'class': [u'sister'], u'id': u
# 'link1'}, 'next_element': u'Elsie', 'parser_class': <class 'bs4.BeautifulSoup'>,
#  'hidden': False, 'contents': [u'Elsie']}
# 
# http://example.com/elsie
# <type 'list'>
# http://example.com/elsie
# http://example.com/elsie

